<template>
  <div class="title-con" ref="titleCon">
    <span class="title-item title-bg"></span>
    <span :class="['title-item', 'title-icon', 'iconfont', icon]"></span>
    <span class="title-item title-txt YouSheBiaoTiHei">
      {{ title }}
    </span>
    <div class="title-item title-btn" v-if="btnArr">
      <blockBtn
        class="btn-item"
        v-for="(item, i) in btnArr"
        :params="item"
        :key="item.key"
        @click.native="btnClick(item.key)"
        :activeKey="
          activeKey ? activeKey : i == btnArr.length - 1 ? item.key : ''
        "
      />
    </div>
  </div>
</template>
<script>
import blockBtn from './blockBtn.vue'
export default {
  name: 'blockTitle',
  components: { blockBtn },
  props: {
    btnGroup: {
      type: Array,
      default: () => []
    },
    title: {
      type: String,
      default: ''
    },
    icon: {
      type: String,
      default: ''
    }
  },
  computed: {
    btnArr() {
      if (!this.btnGroup.length) return false
      let arr = [...this.btnGroup]
      return arr.reverse()
    }
  },
  data() {
    return {
      activeKey: ''
    }
  },
  created() {
    this.$emit('defaultKey', this.btnArr[this.btnArr.length - 1]?.key)
  },
  mounted() {},
  methods: {
    init() {
      let tl = new TimelineMax({})
      let tw = TweenMax.to(this.$refs.titleCon, 0.5, {
        opacity: 1,
        x: '+=100'
      })
      tl.add(tw, 0)
      return tl
    },
    btnClick(key) {
      this.activeKey = key
      this.$emit('btnClick', key)
    }
  }
}
</script>
<style lang="scss" scoped>
.title-con {
  position: absolute;
  height: 36px;
  width: 100%;
  opacity: 0;
  transform: translateX(-100px);
  .title-item {
    position: absolute;
  }
  .title-bg {
    width: 100%;
    height: 100%;
    background: url('../../assets/imgs/project-img/blockTitle/title-bg.png')
      no-repeat;
  }
  .title-txt {
    left: 40px;
    color: #fff;
    line-height: 31px;
    font-size: 28px;
    letter-spacing: 1px;
    font-weight: 400;
  }
  .title-btn {
    position: absolute;
    width: 100%;
    height: 100%;
    .btn-item {
      float: right;
      margin-left: 10px;
    }
  }
  .title-icon {
    color: rgba(9, 109, 217, 1);
    font-size: 26px;
    line-height: 30px;
    left: 3px;
  }
}
</style>
